package com.trigsoft.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class ProcessUtils
{
	public static boolean startedBySelf(String pid, String pkg)
	{
		String line = null;
		try
		{
			String cmd = "ps " + pid;
			Process process = Runtime.getRuntime().exec(cmd);
			BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()), 1024);
			line = bufferedReader.readLine();
			line = bufferedReader.readLine();
			if (line != null)
			{
				String[] fields = line.split(" ");
				String lastField = fields[fields.length - 1];
				if (lastField.compareTo(pkg) != 0)
				{
					return false;
				} else
				{
					return true;
				}
			} else
				return false;
		} catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}

	}
}
